<?php
/**
 * Created by PhpStorm.
 * User: Star
 * Date: 2018-04-16
 * Time: 15:33
 */

namespace App;


use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
    const PAGE_SIZE = 2;
    protected $fillable = ['name','phone','email'];
    /**
     * @param $where_data
     * star_time
     * end_time
     * name
     */
    public function getList($where_data)
    {
        $lists= $this->select('id','name','phone','email','created_at')
            ->where(function($query) use($where_data){
                if (isset($where_data['name'])) {
                    $query->where('name',$where_data['name']);
                }
                if (isset($where_data['start_time'])) {
                    $query->where('created_at','>',$where_data['start_time']);
                }
                if(isset($where_data['end_time'])) {
                    $query->where('created_at','<',$where_data['end_time']);
                }

            })->paginate(self::PAGE_SIZE);
        return $lists;
    }

    public function add($data)
    {
        $this->name = $data['name'];
        $this->phone = $data['phone'];
        $this->email = $data['email'];
        return $this->save();

    }

    public function edit($data)
    {
        $this->name = $data['name'];
        $this->phone = $data['phone'];
        $this->email = $data['email'];
        return $this->save();
    }


    public function remove($id)
    {
        return $this->whereIn('id',$id)->delete();
    }


}